package com.hibase.upms.controller;

import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import com.hibase.core.web.entity.OperationIdsEntity;
import com.hibase.upms.entity.dict.MdsDict;
import com.hibase.upms.entity.dict.vo.*;
import com.hibase.upms.service.dict.MdsDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 字典主表 前端控制器
 * </p>
 *
 * @author chenfeng
 * @since 2021-03-12
 */
@RestController
@RequestMapping("/mds-dict")
@Api(tags = "字典主表")
public class MdsDictController{

    @Autowired
    private MdsDictService mdsDictService;


    @ApiOperation(value = "查询字典主表列表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectMdsDictList")
    public ResponseModel<MdsDictListVO> selectMdsDictList(@RequestBody MdsDictSearchVO searchVO) {

        PageInfo result = mdsDictService.selectMdsDictList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsDictListVO.class));

        return ResponseModel.successMsg(result);
    }


    @ApiOperation(value = "新增字典主表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertMdsDict")
    public ResponseModel<String> insertMdsDict(@RequestBody MdsDictInsertVO insertVO) {

        MdsDict entity = EntityUtil.transform(insertVO, MdsDict.class);

        mdsDictService.saveMdsDict(entity);

        return ResponseModel.successMsg(entity.getId());
    }


    @ApiOperation(value = "修改字典主表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateMdsDict")
    public ResponseModel<String> updateMdsDict(@RequestBody MdsDictUpdateVO updateVO) {

        MdsDict entity = EntityUtil.transform(updateVO, MdsDict.class);

        mdsDictService.saveMdsDict(entity);

        return ResponseModel.successMsg(entity.getId());
    }


    @ApiOperation(value = "查询字典主表详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewMdsDictDetails")
    public ResponseModel<MdsDictViewVO> viewMdsDictDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transform(mdsDictService.viewMdsDict(operationidEntity.getId()), MdsDictViewVO.class));
    }


    @ApiOperation(value = "删除字典主表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deleteMdsDict")
    public ResponseModel<String> deleteMdsDict(@RequestBody OperationIdEntity delete) {

        mdsDictService.deleteMdsDict(delete.getId());

        return ResponseModel.successMsg();
    }


    @ApiOperation(value = "启用字典主表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/enableMdsDict")
    public ResponseModel<String> enableMdsDict(@RequestBody OperationIdsEntity ids) {

        mdsDictService.enableMdsDict(ids.getIds());

        return ResponseModel.successMsg();
    }


    @ApiOperation(value = "禁用字典主表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/disableMdsDict")
    public ResponseModel<String> disableMdsDict(@RequestBody OperationIdsEntity ids) {

        mdsDictService.disableMdsDict(ids.getIds());

        return ResponseModel.successMsg();
    }
}
